home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / c_news / 16 / sets / setsourc / delmembr.c < prev    next >
C/C++ Source or Header  |  1989-03-09  |  942b  |  38 lines

  1. #include <stdio.h>
  2. #include <stdarg.h>
  3. #include "sets.h"
  4. /***************************************************************************/
  5.                 int del_member(set *aset, int member)
  6. /***************************************************************************/
  7. /* resets a bit in the member'th bit place of the set's member record. */
  8. {
  9. int wrd,bit,i;
  10.  
  11.     /* check to see if the set has that many words & members */
  12.     if(member > aset->set_size)
  13.         return FAILURE;
  14.  
  15.     /* get the bit */
  16.     bit = member % MEMBERS_PER_WORD;
  17.  
  18.     /* get the right word */
  19.     i = member / MEMBERS_PER_WORD;
  20.  
  21.     /* test the bit to see if it's already there */
  22.     wrd = 1 << bit;
  23.     if(wrd & aset->word[i] == 0)
  24.         return NOCHANGE;     /* it's already deleted */
  25.     else {
  26.         /* reset the bit */
  27.         aset->word[i] &= ~(1 << bit);
  28.  
  29.         /* update the member count */
  30.         aset->nmembers -= 1;
  31.         }
  32.  
  33.     /* done */
  34.     return SUCCESS;
  35.  
  36. }  /* end del_member */
  37.  
  38.